import BunnyCDNStorage
import time
import os

AccessKey = "b58f0a77-e928-470d-87814423f8b7-6f40-41b0"
cdn_connector = BunnyCDNStorage.CDNConnector(AccessKey, 'apk-test-1')
# 获取文件列表
# list = cdn_connector.get_storaged_objects('/apk')
# for a in list:
#     print(a['ObjectName'])
#     print(a)

# 上传文件
# 文件地址
file_path = "C:/Users/Administrator/Desktop/bunny/jxmtckr975848.apk"
# file_path = "file.txt"
# 您希望上传到的目录的路径
cdn_path = "demo"
# 要在 CDN 中显示的文件名
file_name = '11.apk'
# 开始时间
start_time = int(time.time())
# 获取文件大小
size = os.path.getsize(file_path)
size = round(size / 1024 / 1024, 2)
print("文件大小:" + str(size) + "MB")

res = cdn_connector.upload_file(cdn_path, file_name, file_path)
end_time = int(time.time())
if res['HttpCode'] == 201:
    use_time = end_time - start_time
    print('上传成功用时:' + str(use_time) + '秒')
else:
    print('上传失败')
